package com.pctc.controller;

import com.pctc.domain.Book;
import com.pctc.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/book")
public class BookController {

    @Autowired
    private BookService bookService;

    @RequestMapping("/bookId")
    public ModelAndView findBookById(Integer id) {
        Book book = bookService.findBookById(id);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("book");
        modelAndView.addObject("book", book);
        return modelAndView;
    }



    @RequestMapping("/checkException")
    public String checkException1(@RequestParam("divnum") int divnum) {
        System.out.println("商是: " + (100 / divnum));
         return "success";
    }


    @RequestMapping("/addBook")
    public String addBook(Book book){
        bookService.addBook(book);
        return "success";
    }


}

